/**
 * Created by 小润 on 2017/5/21.
 */
$(document).ready(function(){

    // 显示、隐藏每一项内容
    var index;
    $('.settings-contnet-li').on('click',function(){
        index = $(this).index()-1;
        $('#personnalInfo').hide();
        $('.shows').eq(index).show();
    });
    $('.btn,.go-backk').click(function(){
        $('.shows').eq(index).hide();
        $('#personnalInfo').show();
    });

    //更改昵称
    $('.change-nick').on('click',function(){
        var nickname = $('.name-edit-input input').val();
        $('.nickname').text(nickname);
    });
    //更改手机号
    $('.change-tel').on('click','.btn',function(){
        var tel = $('.change-tel-input input').val();
        $('.tel').text(tel);
    });
    //生日
    $('.brithday').on('click','.btn',function(){
        var brithday = $('.brithday-input input').val();
        $('.brithday-show').text(brithday);
    });
    //祖籍
    $('.zhuji').on('click','.btn',function(){
        var select = $('#city_1 select');
        var ancestor = [];
        $.each(select,function(key,value){
            var val = $(this).val();
            ancestor.push(val+' ');
        });
        ancestor.join('');
        $('.zhuji-show').text(ancestor);
    });
    //住址
    $('.address').on('click','.btn',function(){
        var select1 = $('#city_2 select');
        var address = [];
        $.each(select1,function(key,value){
            var val = $(this).val();
            address.push(val+' ');
        });
        address.join('');
        $('.address-show').text(address);
    });
//    选择性别,添加了遮罩层
    $('.choose-sex').click(function(){
        $('#zhezhaoceng').show();
        $('#close').show();
    });
    $('#zhezhaoceng').click(function(){
        $(this).hide();
        $('#close').hide();
    });
    $('#male').click(function(){
        $('#close').hide();
        $('#zhezhaoceng').hide();
        var value = $('#male').text();
        $('.sex').text(value);
    });
    $('#famale').click(function(){
        $('#close').hide();
        $('#zhezhaoceng').hide();
        var value = $('#famale').text();
        $('.sex').text(value);
    })
    
//  生成二维码
    $("#code").qrcode({ 
	    render: "table", //table方式 
	    width: 200, //宽度 
	    height:200, //高度 
	    text: toUtf8("于经理")//任意内容 
	}); 
		
			
	
//	var str = toUtf8("钓鱼岛是中国的！"); 
//	$('#code').qrcode(str); 

//在二维码编码前，将二维码的内容字符串转换成UTF-8格式
	function toUtf8(str) {    
	    var out, i, len, c;    
	    out = "";    
	    len = str.length;    
	    for(i = 0; i < len; i++) {    
	        c = str.charCodeAt(i);    
	        if ((c >= 0x0001) && (c <= 0x007F)) {    
	            out += str.charAt(i);    
	        } else if (c > 0x07FF) {    
	            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));    
	            out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));    
	            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
	        } else {    
	            out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));    
	            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
	        }    
	    }    
	    return out;    
	} 
});